<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-业务类型</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>基本信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">公司选择</td>
            <td>
<!--                 <select id="companyCombo" class="mini-treeselect w250" textField="companyname"  parentField="parentid"   valueField="id" url="/org/companys" onvaluechanged="view.companyChanged()"/> -->
            <input name="affiliatedCompanyId" id="affiliatedCompanyId" class="mini-treeselect" style="width: 250px; margin-left: 10px;" showTreeIcon="true" valueField="id" textField="companyname"   parentField="parentid" onvaluechanged="view.companyChanged()"   required="true" expandOnLoad="true"  errorMode="none" onvalidation="onChoseValidation" requiredErrorText="请选择"/>
            </td>
            <td class="text-titlebg">部门选择</td>
            <td>
                <input id="officeCombo" class="mini-combobox w250" valueField="id" textField="name"   parentField="parentid" onvaluechanged="view.departmentChanged()">
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">岗位选择</td>
            <td>
                <input id="roleCombo" class="mini-combobox w250" valueField="id" textField="name"   parentField="parentid"  onvaluechanged="view.stationChanged()">
            </td>
            <td class="text-titlebg noEmpty">姓名搜索</td>
            <td>
                <input type="text" name="name" class="mini-textbox w250"/><span class="search-span"></span>
            </td>
        </tr>
    </table>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <tr>
            <td >
                <div id="listbox1" class="mini-listbox" style="width:300px;height:150px;"
                     textField="text" valueField="id" showCheckBox="true" multiSelect="true"
                     >
                </div>
            </td>
            <td style="width:150px;text-align:center;">
                <input type="button" value=">" onclick="view.add()" style="width:40px;"/><br />
                <input type="button" value=">>" onclick="view.addAll()" style="width:40px;"/><br />
                <input type="button" value="&lt;&lt;" onclick="view.removeAll()" style="width:40px;"/><br />
                <input type="button" value="&lt;" onclick="view.removes()" style="width:40px;"/><br />
            </td>
            <td>
                <div id="listbox2" class="mini-listbox" style="width:300px;height:150px;" showCheckBox="true" multiSelect="true" >
                    <!--<div property="columns">-->
                        <!--<div header="ID" field="id"></div>-->
                        <!--<div header="国家" field="text"></div>-->
                    <!--</div>-->
                </div>
            </td>
        </tr>

    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<div id="mask" class="mask-hidden"></div>
<script type="text/javascript">
    var post_flag,form,state,msgState,listbox1,listbox2,status;
    var view = {
        init: function () {
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            msgState = true;
            common.company();
            mini.parse();
            form = new mini.Form("#viewForm");
            //typeNew.SetData(data);
            listbox1 = mini.get("listbox1");
            listbox2 = mini.get("listbox2");
        },
        //添加
        add:function() {
            var items = listbox1.getSelecteds();
            listbox1.removeItems(items);
            listbox2.addItems(items);
        },
        //全部添加
        addAll:function() {
            var items = listbox1.getData();
            listbox1.removeItems(items);
            listbox2.addItems(items);
        },
        //移除
        removes:function() {
            var items = listbox2.getSelecteds();
            listbox2.removeItems(items);
            listbox1.addItems(items);
        },
        //移除全部
        removeAll:function() {
            var items = listbox2.getData();
            listbox2.removeItems(items);
            listbox1.addItems(items);
        },
        //改变公司
        companyChanged: function(){
        	debugger
            var companyCombo = mini.get("affiliatedCompanyId");
            var id = companyCombo.getValue();
            var url = "/org/officesByCompany?companyId=" + id;
            var officeCombo = mini.get('officeCombo');
            officeCombo.setUrl(url);
        },
        //改变部门
        departmentChanged: function(){
            var officeCombo = mini.get("officeCombo");
            var regionCombo = mini.get("roleCombo");
            var id = officeCombo.getValue();
            regionCombo.setValue("");
            var url = "/org/employees?officeId=" + id
            regionCombo.setUrl(url);
        },
        //改变岗位
        stationChanged: function(){
            var cityCombo = mini.get("cityCombo");
            var regionCombo = mini.get("regionCombo");
            var id = cityCombo.getValue();
            /*regionCombo.setValue("");
            var url = "/region/listByCity?cityId=" + id
            regionCombo.setUrl(url);*/
        },
        //保存
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            if(msgState==""){
                mini.alert("该业务类型已经存在，请重新输入");
                return;
            }
            var data = form.getData();//获取表单多个控件的数据
            post_flag = true;
            $.ajax({
                url: (state=="new"?"/businessType/add":"/businessType/edit?id=" + data.id),
                type: "post",
                data: data,
                success: function (data) {
                    if(!data.state){
                        mini.alert(data.message);
                    }
                    post_flag = false;
                    CloseWindow("ok")
                },
                error: function (errorMsg) {
                    post_flag = false;
                    var msg  = JSON.parse(errorMsg.responseText);
                    common.prompt(msg.message);
                }
            });
        },
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
        	status = data.status;//status如果是0代表此处是需要单选的
          var  affiliatedCompanyId = data.affiliatedCompanyId;
          mini.get("affiliatedCompanyId").setValue(affiliatedCompanyId);
          view.companyChanged();
        }
    };
    view.init();
</script>
</body>
</html>